<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
/**
 * Result
 * 
 * Represents a result set of scored entities.
 */
class entityresolution_Result
{
	/**
	 * Result entries.
	 * @var array[string]entityresolution_ResultEntry
	 */
	protected $entries = array();
	
	/**
	 * Add a result entry. Existing entries with the same subject URI but a lower difference score will not be overwritten. 
	 * @param entityresolution_ResultEntry $resultEntry result entry
	 */
	public function addEntry($resultEntry)
	{
		/* @var $existingResultEntry entityresolution_ResultEntry */
		$existingResultEntry = $this->entries[$resultEntry->getSubjectUri()];
		if($existingResultEntry === null || $existingResultEntry->getScore() === null || $existingResultEntry->getScore() > $resultEntry->getScore())
		{
			$this->entries[$resultEntry->getSubjectUri()] = $resultEntry;
		}
	}

	/**
	 * Get the result entries, ordered by difference score.
	 * @param $limit limit
	 * @return array[int]entityresolution_ResultEntry result entries
	 */
	public function getEntries($limit = 0)
	{
		uasort($this->entries, array('entityresolution_ResultEntry', 'compareScores'));
		
		if($limit)
		{
			return array_slice($this->entries, 0, $limit);
		}
		else
		{
			return $this->entries;
		}
	}
}